package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.business.domain.CarPackageAudit;
import cn.wolfcode.car.business.domain.HistoricComment;
import cn.wolfcode.car.business.query.CarPackageAuditQuery;
import cn.wolfcode.car.business.service.ICarPackageAuditService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

@Controller
@RequestMapping("/business/carPackageAudit")
public class CarPackageAuditController {
    //前缀
    private static final String prefix = "/business/carPackageAudit/";
    @Autowired
    private ICarPackageAuditService carPackageAuditService;

    /***************************   进入页面开始    *****************************/
    //列表
    @RequestMapping("/listPage")
    public String list() {
        return prefix + "list";
    }
    //我的代办页面
    @RequestMapping("/todoPage")
    public String todoPage(){
        return prefix + "todoPage";
    }
    //进入审批页面
    @RequestMapping("/auditPage")
    public String auditPage(Long id, Model model){
        model.addAttribute("id",id);
        return prefix + "auditPage";
    }
    //进入审批历史页面
    @RequestMapping("/historyList")
    public String historyList(String instanceId,Model model){
        model.addAttribute("instanceId",instanceId);
        return prefix + "historyList";
    }
    //进入我的已办页面
    @RequestMapping("/donePage")
    public String donePage(){
        return prefix + "donePage";
    }

    /***************************   进入页面结束    *****************************/

    //分页查询 功能
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<CarPackageAudit> query(CarPackageAuditQuery qo) {
        return carPackageAuditService.query(qo);
    }

    //进度查看
    @RequestMapping("/processImg")
    @ResponseBody
    public void processImg(Long id, HttpServletResponse response) throws IOException {
        InputStream is = carPackageAuditService.processImg(id);
        IOUtils.copy(is, response.getOutputStream());
    }

    //撤销
    @RequestMapping("/cancelApply")
    @ResponseBody
    public AjaxResult cancelApply(Long id){
        carPackageAuditService.cancelApply(id);
        return AjaxResult.success();
    }
    //我的代办 列表分页查询
    @RequestMapping("/todoQuery")
    @ResponseBody
    public TablePageInfo<CarPackageAudit> todoQuery(CarPackageAuditQuery qo){
            //查询当前审核人 的状态信息
      return carPackageAuditService.todoQuery(qo);
    }
    //审批功能实现
    @RequestMapping("/audit")
    @ResponseBody
    public AjaxResult audit(Long id,String auditStatus,String info){
        carPackageAuditService.audit(id,auditStatus,info);
        return AjaxResult.success();
    }
    //查看审批历史
    @RequestMapping("/listHistory")
    @ResponseBody
    public TablePageInfo<HistoricComment> listHistory(String instanceId){
            return carPackageAuditService.listHistory(instanceId);
    }
    //我的已办列表
    @RequestMapping("/doneQuery")
    @ResponseBody
    public TablePageInfo<CarPackageAudit> doneQuery(CarPackageAuditQuery qo){
        return carPackageAuditService.doneQuery(qo);
    }

}
